package com.ds.persist.vo.http;

import net.sf.json.JSONObject;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * Created by zhangyou on 2019/1/4.
 */
public class RespModel {

    private int status;

    private JSONObject data = new JSONObject();

    private String error;


    public void setData(Object data) {
        this.data =JSONObject.fromObject(data);
        this.status = 1;
    }

    public void addError(BindingResult br){
        ObjectError objectError = br.getAllErrors().get(0);
        error = objectError.getDefaultMessage();
        this.status = 0;
    }

    public JSONObject toJSON(){
        return JSONObject.fromObject(this);
    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }
}
